//
//  L2Date.m
//  Lesson2
//
//  Created by Alexander Trifonov on 20.04.12.
//  Copyright (c) 2012 fgengine@gmail.com. All rights reserved.
//

#import "L2Date.h"

@implementation L2Date

- (void) execute
{
    NSLog(@"-L2Date---------------------------------");
    
    NSDate *currentDate = [NSDate date];
    NSLog(@"%@", currentDate);
    
    NSLog(@"----------------------------------------");
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter new] autorelease];
    [dateFormatter setDateStyle:kCFDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:kCFDateFormatterShortStyle];
    NSString *strDate = [dateFormatter stringFromDate:currentDate];
    NSLog(@"%@", strDate);
    
    NSLog(@"----------------------------------------");
    
    [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];
    NSLog(@"%@", [dateFormatter stringFromDate:currentDate]);
    
    NSLog(@"----------------------------------------");
    
    NSString *currentStrDate = @"2008/08/18 13-45-01";
    NSDateFormatter *dateFormatterStr = [[NSDateFormatter new] autorelease];
    [dateFormatterStr setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    [dateFormatterStr setDateFormat:@"yyyy/MM/dd HH-mm-ss"];
    NSDate *dateFromStr = [dateFormatterStr dateFromString:currentStrDate];
    NSLog(@"%@", dateFromStr);
    
    NSLog(@"----------------------------------------");
    
    NSDate *newDate = [currentDate dateByAddingTimeInterval:60*60*24];
    NSLog(@"%@", newDate);
    
    NSLog(@"----------------------------------------");
    
    BOOL equal = [currentDate isEqualToDate:newDate];
    NSLog(@"%i", equal);
    
    NSLog(@"----------------------------------------");
    
    NSLog(@"earlier:%@", [currentDate earlierDate:newDate]);
    NSLog(@"later:%@", [currentDate laterDate:newDate]);
    
    NSLog(@"----------------------------------------");
}

@end
